Completed
Push — master ( 971150...516dcf )
by
unknown
02:45
created

lock.js ➔ deleteAll   A

Complexity

Conditions 1
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
nc 2
dl 0
loc 8
rs 9.4285
nop 0

1 Function

Rating   Name   Duplication   Size   Complexity  
A lock.js ➔ ... ➔ ??? 0 5 3
1
import process from 'child_process'
2
import path from 'path'
3
import fs from 'fs'
4
5
import {
6
  config
7
  ,abeExtend
0 ignored issues
show
Unused Code introduced by
The variable abeExtend seems to be never used. Consider removing it.
Loading history...
8
} from '../'
9
10
export function create(name) {
11
  let lockFile = path.join(config.root, `abe-process-${name}.lock`)
12
  try {
13
    var stats = fs.statSync(lockFile)
14
    if (stats.isFile()) {
15
      console.log(`cannot lock process ${name} already running`)
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
16
      return false
17
    }
18
  }catch(err) {
19
    fs.writeFileSync(lockFile, '', {encoding: 'utf8'})
20
  }
21
22
  return true
23
}
24
25
export function remove(name) {
26
  let lockFile = path.join(config.root, `abe-process-${name}.lock`)
27
  try {
28
    var stats = fs.statSync(lockFile)
29
    if (stats.isFile()) {
30
      fs.unlinkSync(lockFile)
31
      return true
32
    }
33
  }catch(err) {
0 ignored issues
show
Coding Style Comprehensibility Best Practice introduced by
Empty catch clauses should be used with caution; consider adding a comment why this is needed.
Loading history...
34
    
35
  }
36
  return false
37
}
38
39
export function deleteAll() {
40
  var files = fs.readdirSync(config.root)
41
  Array.prototype.forEach.call(files, (file) => {
42
    if (file.indexOf('abe-process') > -1 && file.indexOf('.lock') > -1) {
43
      fs.unlinkSync(path.join(config.root, file))
44
    }
45
  })
46
}